package com.mew.chess.core.game.yxx.game.common;

import lombok.ToString;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@ToString
public enum YxxBetType {

    Fish_Shrimp(0,YxxType.create(1,2)),
    Gourd_Chicken(1,YxxType.create(5,6)),
    Crab_Tiger(2,YxxType.create(3,4)),
    Shrimp_Tiger(3,YxxType.create(2,4)),
    Gourd(4,YxxType.create(5)),
    Fish_Gourd(5,YxxType.create(1,5)),
    Tiger_Gourd(6,YxxType.create(4,5)),
    Tiger(7,YxxType.create(4)),
    Tiger_Chicken(8,YxxType.create(4,6)),
    Crab(9,YxxType.create(3)),
    Fish_Crab(10,YxxType.create(1,3)),
    Fish_Chicken(11,YxxType.create(1,6)),
    Chicken(12,YxxType.create(6)),
    Chicken_Shrimp(13,YxxType.create(2,6)),
    Fish(14,YxxType.create(1)),
    Shrimp_Crab(15,YxxType.create(2,3)),
    Shrimp(16,YxxType.create(2)),
    Shrimp_Gourd(17,YxxType.create(2,5)),
    Crab_Chicken(18,YxxType.create(3,6)),
    Crab_Gourd(19,YxxType.create(3,5)),
    Fish_Tiger(20,YxxType.create(1,4));

    private final int code;
    private final YxxType[] types;

    YxxBetType(final int code,final YxxType[] types) {
        this.code = code;
        this.types = types;
    }

    private final static Map<Integer, YxxBetType> stateMap
            = Arrays.stream(YxxBetType.values()).collect(Collectors.toMap(YxxBetType::code, code -> code));

    public int code() {
        return this.code;
    }
    public YxxType[] types() {
        return this.types;
    }
    public int[] typesInt() {
        int[] ints = new int[this.types.length];
        for (int i = 0; i < this.types.length; i++) {
            ints[i] = this.types[i].code();
        }
        return ints;
    }

    public static YxxBetType parse(int code) {
        return stateMap.getOrDefault(code, YxxBetType.Fish_Shrimp);
    }


}
